package com.atguigu.cloud.controller;

import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: PatController
 * Package: com.atguigu.cloud.controller
 * Description:
 *
 * @Author 加油-ssj
 * @Create 2025/3/11 18:04
 * @Version 1.0
 */
@RestController
@Slf4j
@Tag(name = "支付流水订单模块",description = "支付crud")
public class PayController {

    @Resource
    private PayService payService;

    @PostMapping(value = "/pay/add")
    @Operation(summary = "新增",description = "新增支付流水方法，json参数")
    public ResultData<String> addPay(@RequestBody Pay pay) {
        System.out.println(pay.toString());
        int i = payService.insert(pay);
        return ResultData.success("成功插入记录，返回值："+i);
    }

    @DeleteMapping(value = "/pay/del/{id}")
    @Operation(summary = "删除",description = "删除支付流水方法")
    public ResultData<Integer> deletePay(@PathVariable("id") Integer id) {

        int delete = payService.delete(id);
        return ResultData.success(delete);
    }

    @PutMapping(value = "/pay/update")
    @Operation(summary = "修改",description = "修改支付流水方法")
    public  ResultData<String> updatePay(@RequestBody PayDTO payDTO) {
        Pay pay = new Pay();
        BeanUtils.copyProperties(payDTO, pay);

        int i = payService.update(pay);
        return ResultData.success("成功修改记录，返回值："+i);
    }

    @GetMapping(value = "/pay/get/{id}")
    @Operation(summary = "根据id查询",description = "根据id查询支付流水方法")
    public ResultData<Pay> getById(@PathVariable("id") Integer id) {
   //     int i=10/0;
        Pay pay = payService.getPay(id);
        return ResultData.success(pay);

    }

    @GetMapping("/pay/getAll")
    @Operation(summary = "查询",description = "查询所有支付流水方法")
    public ResultData<List<Pay>> getAll() {
        List<Pay> all = payService.getAll();
        return ResultData.success(all);

    }

    @Value("${server.port}")
    private String port;

    @GetMapping(value = "/pay/get/info")
    private String getInfoByConsul(@Value("${atguigu.info}") String atguiguInfo)
    {
        return "atguiguInfo: "+atguiguInfo+"\t"+"port: "+port;
    }
}

//    @Resource
//    private PayService payService;
//
//
//    @PostMapping("/pay/add")
//    public String add(@RequestBody Pay pay){
//
//        int insert = payService.insert(pay);
//
//        return "成功插入记录，返回值为"+insert;
//    }
//
//    @DeleteMapping("/pay/delete/{id}")
//    public int delete(@PathVariable("id") Integer id){
//        int delete = payService.delete(id);
//        return delete;
//    }
//
//    @PutMapping("/pay/update")
//    public String update(@RequestBody PayDTO payDTO){
//        Pay pay=new Pay();
//        BeanUtils.copyProperties(payDTO,pay);
//        int update = payService.update(pay);
//        return "成功修改记录，返回值为"+update;
//    }
//
////    @GetMapping(value = "/pay/get/{id}")
////    public Pay getId(@PathVariable("id") Integer id){
////        Pay pay = payService.getPay(id);
////        return pay;
////    }
//
//    @GetMapping(value = "/pay/get/{id}")
//    public Pay getById(@PathVariable("id") Integer id) {
//        return payService.getPay(id);
//    }
//
//    @GetMapping("/pay/getAll")
//    public List<Pay> getAll(){
//
//        List<Pay> all = payService.getAll();
//        return all;
//    }




